const productmodel = require("../../modle/products")
const usermodel = require('../../modle/user')
const ordermodel = require('../../modle/order')
module.exports = {
    async getproduct() {
        return await productmodel.findAll()
    },
    async setproductstatus(id, status) {
        return await productmodel.update({
            status
        }, {
            where: {
                id
            }
        })
    },
    async getuser() {
        return await usermodel.findAll()
    },
    async getprice(id) {
        const rudata = await ordermodel.findAll({
            where: {
                userid: id
            }
        })
        return rudata.reduce((pre, cur) => {
            return pre + cur.allprice
        }, 0)
    }
}